//
//  BaseTableViewController.swift
//  HJWeibo
//
//  Created by huangjiong on 16/1/31.
//  Copyright © 2016年 huangjiong. All rights reserved.
//

import UIKit
import AFNetworking

class BaseTableViewController: UITableViewController,VisitorViewDelegate {

    
    //定义一个变量,用于判断用户当前是否已经登录
    var userLogin = UserAccount.userIsLogin()
    
    //定义一个属性,用于保存未登录界面的view
    var visitorView: VisitorView?
    
    override func loadView() {
        
        userLogin ? super.loadView() : setupVisitorView()
        
    }
    
    //MARK: - 内部控制方法
    //用于创建未登录界面
    private func setupVisitorView()
    {
        let customView = VisitorView()
        customView.delegate = self
        view = customView
        visitorView = customView
        
        //设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerButtonDidClicked")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginButtonDidClicked")
    }
    
    //VisitorViewDelegate
    //注册
    func registerButtonDidClicked() {
        print("注册")
    }
    
    //登录
    func loginButtonDidClicked() {
        
        let oauthVC = OAuthViewController()
        let nav = UINavigationController(rootViewController: oauthVC)
        presentViewController(nav, animated: true, completion: nil)
    }
}
